package com.android.mensa.models;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.android.mensa.R;

public class DayAdapter extends ArrayAdapter<Meal> {

	private ArrayList<Meal> mData = new ArrayList<Meal>();
	private LayoutInflater mInflater;

	public DayAdapter(Context context, int textViewResourceId, List<Meal> objects) {
		super(context, textViewResourceId, objects);

		mData = new ArrayList<Meal>(objects);		
		mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public boolean isEnabled(int position) {
		return false;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View v = convertView;
		Meal meal = mData.get(position);
		MenuViewHolder holder = null;
		if (v == null) {
			v = mInflater.inflate(R.layout.menu, null);
			
			holder = new MenuViewHolder();
			holder.setMenuNameView((TextView)v.findViewById(R.id.menu_name));
			holder.setSoupView((TextView)v.findViewById(R.id.soup));
			holder.setMainDishView((TextView)v.findViewById(R.id.maindish));
			holder.setSideDishView((TextView)v.findViewById(R.id.sidedish));
			v.setTag(holder);
		}
		else
			holder = (MenuViewHolder)v.getTag();
		
		holder.getMenuNameView().setText(meal.getMenuName());
		holder.getSoupView().setText(meal.getSoup());
		holder.getMainDishView().setText(meal.getMainDish());
		holder.getSideDishView().setText(meal.getSideDish());		
		return v;
	}

}
